<template>
  <div style="margin-top: 10px" class="app-contain">
    <el-row :gutter="50">
      
      <el-col :span="17">
       
          <el-tabs active-name="event" type="card">
            <!-- <el-tab-pane label="用户动态" name="event">
              <div class="block">
                <el-timeline>
                  <el-timeline-item  :timestamp="item.createTime" placement="top" :key="item.id" v-for="item in event">
                    <el-card>
                      <p>{{item.content}}</p>
                    </el-card>
                  </el-timeline-item>
                </el-timeline>
              </div>
            </el-tab-pane> -->
            <el-tab-pane label="意见反馈" name="event">
              <el-form :model="form" ref="form" label-width="100px" v-loading="formLoading" :rules="rules">

                  <el-form-item label="标题：" required  prop="title">
                  <el-input v-model="form.title"></el-input>
                </el-form-item>

                <el-form-item label="内容：" required  prop="content">
                  <el-input
                show-word-limit
                maxlength="300"
                    class="public-showWordLimit"
                :autosize = "{ minRows: 2, maxRows: 8 }"
                  
                    type="textarea"
                    v-model="form.content">
                  </el-input>

           
                </el-form-item>
             
             
                <el-form-item label="手机号：" required  prop="phone">
                  <el-input v-model="form.phone"></el-input>
                </el-form-item>
                <!-- <el-form-item label="年级：" prop="userLevel" required>
                  <el-select v-model="form.userLevel" placeholder="年级">
                    <el-option v-for="item in levelEnum" :key="item.key" :value="item.key"
                               :label="item.value"></el-option>
                  </el-select>
                </el-form-item> -->
                <el-form-item>
                  <el-button type="primary" @click="submitForm">反馈</el-button>
                </el-form-item>
              </el-form>
            </el-tab-pane>
          </el-tabs>
     
      </el-col>
    </el-row>
  </div>
</template>

<script>
import userApi from '@/api/user'
import { mapGetters, mapState } from 'vuex'

export default {
  data () {
    return {
      event: [],
      form: {
        userName: '',
        realName: '',
        age: '',
        sex: '',
        email: '',
        birthDay: null,
        phone: null,
        userLevel: null,
        createTime: null,
        imagePath: null
      },
      formLoading: false,
      rules: {
        realName: [
          { required: true, message: '请输入真实姓名', trigger: 'blur' }
        ],
        email: [
          {
            required: true,
            message: '请输入邮箱',
            trigger: 'blur'
          },
          {
            validator: function (rule, value, callback) {
              if (
                /^\w{1,64}@[ a-z0-9\- ]{1,256}(\.[a-z]{2,6}){1,2}$/i.test(value) === false
              ) {
                callback(new Error('请输入正确的邮箱'))
              } else {
                callback()
              }
            },
            trigger: 'blur'
          }
        ],
        phone: [
          {
            required: true,
            message: '请输入手机号码',
            trigger: 'blur'
          },
          {
            validator: function (rule, value, callback) {
              if (/^1[34578]\d{9}$/.test(value) === false) {
                callback(new Error('手机号格式错误'))
              } else {
                callback()
              }
            },
            trigger: 'blur'
          }
        ]
      }
    }
  },
  created () {
    let _this = this
    userApi.getUserEvent().then(re => {
      _this.event = re.response
    })
    userApi.getCurrentUser().then(re => {
    //  _this.form = re.response
    })
  },
  methods: {
    uploadSuccess (re, file) {
      if (re.code === 1) {
        window.location.reload()
      } else {
        this.$message.error(re.message)
      }
    },
    submitForm () {
      let _this = this
      this.$refs.form.validate((valid) => {
        if (valid) {
          this.formLoading = true
          userApi.advice(this.form).then(data => {
            if (data.code === 1) {
              _this.$message.success(data.message)
            } else {
              _this.$message.error(data.message)
            }
            _this.formLoading = false
          }).catch(e => {
            _this.formLoading = false
          })
        } else {
          return false
        }
      })
    },
    levelFormatter (level) {
      return this.enumFormat(this.levelEnum, level)
    }
  },
  computed: {
    ...mapGetters('enumItem', [
      'enumFormat'
    ]),
    ...mapState('enumItem', {
      sexEnum: state => state.user.sexEnum,
      levelEnum: state => state.user.levelEnum
    })
  }
}
</script>

<style lang="scss" scoped>

</style>
